package com.shiro.test;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import org.junit.Test;
import org.mybatis.generator.api.MyBatisGenerator;
import org.mybatis.generator.config.Configuration;
import org.mybatis.generator.config.xml.ConfigurationParser;
import org.mybatis.generator.internal.DefaultShellCallback;

import com.shiro.pojo.UserBean;

public class MybatisToJava {
	@Test//逆向工程代码
    public void test1() throws Exception{
        //System.out.println("测试的方法test1");
        List<String> warnings = new ArrayList<String>();
        boolean overwrite = true;
        //项目根路径不要有中文,我的有中文,所以使用绝对路径
        File configFile = new File("D://config.xml");
        ConfigurationParser cp = new ConfigurationParser(warnings);
        Configuration config = cp.parseConfiguration(configFile);
        DefaultShellCallback callback = new DefaultShellCallback(overwrite);
        MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, callback, warnings);
        myBatisGenerator.generate(null);
    }
	@Test
	public void test2(){
		UserBean user = new UserBean();
		user.setId(1);
		user.setUsername("tom");
		System.out.println("username:"+user.getUsername());
		String string = user.getUsername();
		System.out.println("取出来的username:"+string);
		string = "nidayede";
		System.out.println("修改后的username："+string);
		System.out.println("从user中最后取出的username:"+user.getUsername());
	}
}
